package cn.wolfcode.crm.util;

import cn.wolfcode.crm.domain.Employee;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;
import java.util.List;

public abstract class UserContext {

    public static final String EMPLOYEE_IN_SESSION = "EMPLOYEE_IN_SESSION";
    public static final String EXPRESSION_IN_SESSION = "EXPRESSION_IN_SESSION";

    public static HttpSession getSession(){
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
        return requestAttributes.getRequest().getSession();
    }
    public static void removeSession() {
        getSession().invalidate();
    }

    public static void setEmployee(Employee employee) {
        getSession().setAttribute("EMPLOYEE_IN_SESSION",employee);
    }

    public static Employee getEmployee(){
        return (Employee)getSession().getAttribute("EMPLOYEE_IN_SESSION");
    }

    public static void setExpression(List<String> list) {
        getSession().setAttribute("EXPRESSION_IN_SESSION",list);
    }

    public static List<String>  getExpression(){
        return (List<String>)getSession().getAttribute("EXPRESSION_IN_SESSION");
    }
}
